import tkinter as tk

from tkinter import *
from indexPage import *
from listPage import *
from config import *


def main():
    # 创建一个窗口
    root = Tk()
    # 设置窗口标题
    root.title('TAPTAP')
    root.geometry('%dx%d' % (1200, 800))
    # 创建菜单栏
    menubar = tk.Menu(root)
    # 创建菜单选项
    # menubar.add_command(label='爬取新数据', command=update_list)
    # 创建菜单栏后配置让该菜单栏显示
    root.config(menu=menubar)
    root.winfo_height()
    root.winfo_width()
    ListPage(root)
    root.mainloop()


# 菜单栏点击事件
def update_list():
        try:
            url = '/updateList'
            headers = {'user-agent': Config.get_ua(Config)}
            ret = requests.get(Config.beas_url + url, headers=headers)
            retJson = json.loads(ret.text)
            if retJson.get('code') == 200:
                print(200)
                tkinter.messagebox.showinfo('提示', '爬取数据任务已开启')
            else:
                print(500)
                tkinter.messagebox.showerror('错误', '网络异常')
        except Exception as e:
            print(e)
            a = tkinter.messagebox.showerror('错误', '网络异常')


main()
